<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt" style="padding-top: 100rpx; margin: 0">
			<view class="uni-center" style=" font-size:0;">
				<image class="image" src="/static/logo.png" />
			</view>

			<view class="uni-form-item uni-column" style="margin-top: 30px;">

				<view class="example">
					<uni-easyinput prefixIcon="person" v-model="account" placeholder="请输入账号" @iconClick="iconClick">
					</uni-easyinput>
				</view>
				<view class="example" style="margin-top: 15rpx;">
					<uni-easyinput prefixIcon="info" v-model="pwd" placeholder="请输入密码" @iconClick="iconClick"
						type="password" @confirm="Submit">
					</uni-easyinput>


				</view>

				<view class="example" style="margin-top: 30px;">
					<button type="primary" @click="Submit">登录</button>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '物资收发一体柜APP',
				account: '',
				pwd: ''

			}
		},
		methods: {

			Submit: function() {

				if(this.account == '' || this.pwd == '') {
					uni.showToast({
						title: "账号或者密码不能为空",
						icon: 'none'
					})
					return
				}
				uni.request({
					url:  this.url+'GetUser',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
					},
					method: 'POST',
					dataType: 'json',
					data: {
						account: this.account,
						pwd: this.pwd
					},
					success: (res) => {

						if (res.statusCode == 200 && res.data!=null) {

							this.StorageCache('user', res.data, 28) //存入缓存，最后一个参数是缓存过期时间

							// let value = this.StorageCache('user')

							uni.switchTab({
								url: '/pages/cupboard/index',
								success() {
									let page = getCurrentPages().pop(); //跳转页面成功之后
									if (!page) return;
									location.reload()
								}
							})

						} else {
							uni.showToast({
								title: "账号或者密码不正确",
								icon: 'none',
							});
						}

					},
					complete: (res) => {
				
					}
				});

			}

		}

	}
</script>

<style>
	.image {
		margin: 40rpx 0;
		width: 72px;
		height: 72px;
	}
</style>
